<?php

namespace App\Admin\Forms;

use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use App\Models\WxFeedback as FeedbackModel;
use App\Models\WxNotice as NoticeModel;

class CommenForms extends Form implements LazyRenderable
{
    use LazyWidget;


    /**
     * 主题颜色.
     *
     * @var array
     */
    protected $colors = [
        'default' => '深蓝',
        'blue' => '蓝',
//        'blue-light' => '浅蓝',
//        'blue-dark'  => '深蓝',
        'green' => '绿',
    ];

    /**
     * 处理表单请求.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        $feedbackModel = new FeedbackModel;
        $feedback = $feedbackModel->where('id', $input['id'])->first();
        $feedback->feedback_reply = $input['feedback_reply'];
        $feedback->feedback_state = 1;
        $feedback->save();

        $uid = FeedbackModel::where('id', $input['id'])->value('user_id');
        $noticeModel = new NoticeModel;
        $noticeModel->user_id = $uid;
        $noticeModel->title = $input['title'];
        $noticeModel->content = $input['feedback_reply'];
        $noticeModel->is_read = 0;
        $noticeModel->notice_type = 0;
        $noticeModel->save();


        return $this->response()
            ->success('Processed successfully.')
            ->refresh();
    }

    /**
     * 构建表单.
     */
    public function form()
    {
        $this->hidden('id')->value($this->payload["id"]);
        $this->text('title', "回复标题");
        $this->textarea('feedback_reply', "回复内容");
    }

}
